<?php
	include_once dirname(dirname(dirname(__FILE__))).'/inc/bootConfig.php';
	include_once '../checkLogin.php';
	include_once '../Public/login/checkUserGrade.php';
	
	userLimit($username,1);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
<!--
body {
	margin-left: 3px;
	margin-top: 0px;
	margin-right: 3px;
	margin-bottom: 0px;
}
.STYLE1 {
	color: #e1e2e3;
	font-size: 12px;
}
.STYLE6 {color: #000000; font-size: 12; }
.STYLE10 {color: #000000; font-size: 12px; }
.STYLE19 {
	color: #344b50;
	font-size: 12px;
}
.STYLE21 {
	font-size: 12px;
	color: #3b6375;
}
.STYLE22 {
	font-size: 12px;
	color: #295568;
}
-->
</style>
</head>

<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="30"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="24" bgcolor="#353c44">
        <?php 
    		include_once 'inc/userinfotop.html';
    	?></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td>
    <form action="" method="post" id="form1" onsubmit="return checkinfo();">
	   <table width="100%" align="center" border="0" cellpadding="0" cellspacing="1" bgcolor="#a8c7ce">
	   	  <tr>
	        <td height="40"  bgcolor="d3eaef" class="STYLE6"  colspan='2' align="center"><h3>添加后台管理员</h3></td>
	      </tr>
	      <tr>
	        <td width="40%" height="20" bgcolor="#FFFFFF"  class="STYLE6"><div align="right"><span class="STYLE10">登录名称：</span></div></td>
	        <td width="60%" height="20" bgcolor="#FFFFFF"  class="STYLE6">
				<input type="text" value="" name="username" size="16" id="usname"/>
			</td>
	      </tr>
	      <tr>
	        <td width="40%" height="20" bgcolor="#FFFFFF"  class="STYLE6"><div align="right"><span class="STYLE10">登录密码：</span></div></td>
	        <td width="60%" height="20" bgcolor="#FFFFFF"  class="STYLE6">
				<input type="password" value="" name="userpwd" size="16" id="uspwd"/>
			</td>
	      </tr>
	      <tr>
	        <td width="40%" height="20" bgcolor="#FFFFFF"  class="STYLE6"><div align="right"><span class="STYLE10">用户真实姓名：</span></div></td>
	        <td width="60%" height="20" bgcolor="#FFFFFF"  class="STYLE6">
				<input type="text" value="" name="realname" size="16" id="usrealname"/>
			</td>
	      </tr>
	      <tr>
	        <td width="40%" height="20" bgcolor="#FFFFFF"  class="STYLE6"><div align="right"><span class="STYLE10">用户管理等级：</span></div></td>
	        <td width="60%" height="20" bgcolor="#FFFFFF"  class="STYLE6">
	        	<select name="usergrade" id="usgrade">
	        		<option value='0'>超级管理员</option>
	        		<option value='1'>管理员</option>
	        		<option value='2' selected>会员</option>
	        	</select>
			</td>
	      </tr>
	      <tr>
	        <td width="40%" height="20" bgcolor="#FFFFFF"  class="STYLE6"><div align="right"><span class="STYLE10">手机号：</span></div></td>
	        <td width="60%" height="20" bgcolor="#FFFFFF"  class="STYLE6">
				<input type="text" value="" name="userphone" size="16" id="usphone"/>
			</td>
	      </tr>
	      <tr>
	        <td width="40%" height="20" bgcolor="#FFFFFF"  class="STYLE6"></td>
	        <td width="60%" height="20" bgcolor="#FFFFFF"  class="STYLE6">
				<input type="submit" value="提交" name="submit" id="submit_s"/>
				<input type="reset" value="重置" name="reset" id="reset_s"/>
				<input type="button" value="返回" name="reset" id="reset_s" onclick="location.href='userList.php'"/>
			</td>
	      </tr>
      </table>
      </form>
	</td>
  </tr>
</table>
</body>
</html>
<script type="text/javascript">
<!--
function checkinfo(){
	var form = document.getElementById('form1');
	if(form.username.value.length<1){
		alert('请输入用户名');
		form.username.focus;
		return false;
	}
	if(form.userpwd.value.length<1){
		alert('请输入用户登录密码');
		form.userpwd.focus;
		return false;
	}
	if(form.realname.value.length<1){
		alert('请输入用户真实姓名');
		form.realname.focus;
		return false;
	}
	if(form.userphone.value.length<1){
		alert('请输入用户手机号');
		form.userphone.focus;
		return false;
	}
	if(!checkphone(form.userphone.value)){
		alert('请输入正确的手机号码');
		return false;
	}
}
function checkphone(phone){
	var reg =/^1[3,5,8]\d{9}$/;
	if(reg.test(phone)){
		return true;
	}
	return false; 
}
//-->
</script>
<?php 
	if(isset($_POST['submit'])&&$_POST['submit']&&!empty($_POST['username'])&&!empty($_POST['userpwd'])){
		if(!User_User::getAdminUserInfo($_POST['username'])){
			if(User_User::insertAdminUser($_POST)){
				jstop('用户添加成功');
			}else{
				jstop('数据异常，请重试！');
			}
		}else{
			jstop('用户名已存在，请重新输入 ');
		}
	}
?>
	
	